package reflectasm;

import java.lang.reflect.Method;
import com.esotericsoftware.reflectasm.MethodAccess;
 
/**
 * @author Unmi
 */
public class ReflectasmClient {
 
    public static void main(String[] args) throws Exception {
        
    	System.out.println("JdkReflect");
    	testJdkReflect();
    	 System.out.println();
        System.out.println("ReflectAsm");
        testReflectAsm();
    }
     
    public static void testJdkReflect() throws Exception {
        SomeClass someObject = new SomeClass();        
        Method method = SomeClass.class.getMethod("foo", String.class);
        
        for (int i = 0; i < 5; i++) {
            long begin = System.currentTimeMillis();
            
            for (int j = 0; j < 100000; j++) {
                method.invoke(someObject, "Unmi");
            }
            System.out.print(System.currentTimeMillis() - begin +" ");
        }
    }
 
    public static void testReflectAsm() {
        SomeClass someObject = new SomeClass();
        MethodAccess access = MethodAccess.get(SomeClass.class);
        int fooIndex = access.getIndex("foo", String.class);
        for (int i = 0; i < 5; i++) {
            long begin = System.currentTimeMillis();
           
            for (int j = 0; j < 100000; j++) {
               access.invoke(someObject, fooIndex, "Unmi");
            }
            System.out.print(System.currentTimeMillis() - begin + " ");
        }
    }
}
